/**
 * Created by guosc on 2016/11/4 0004.
 */
define([
    'require',
    'angular',
    'underscore'
], function (require, angular, _) {
    return  function ($scope, $rootScope, $routeParams, Resource, GillionMsg, RuleSerivce) {
        var decisionTree=Resource("/grule-manager/decisionTrees/:id",{
            id:"@id"
        });

        RuleSerivce.promises().then(function () {
            $scope.status=$rootScope.currPackage.status;
            $scope.decisionTree=$rootScope.currDecisionTree;
        });

        $scope.reset=function(){
            decisionTree.get({
                id:$routeParams.treeId
            },function(resp){
                $scope.decisionTree=resp.data;
            });
        }

        $scope.save=function(){
            angular.element('form[name="DecisionTreeForm"]').scope().DecisionTreeForm.verify().then(function(){
                Resource("/grule-manager/decisionTrees/"+$scope.decisionTree.id).update($scope.decisionTree,function(resp){
                    if(resp.success){
                        GillionMsg.alert("提示","保存成功！");
                        RuleSerivce.setCurrentDecisionTree($scope.decisionTree);
                        angular.element(document).trigger('refresh.menu');
                    }
                })
            });
        };

    }
});


